package com.ymatou.productstock.api.testcase;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.productstock.api.parameter.CatalogBean;
import com.ymatou.productstock.api.service.AllocateProductActivityStockCall;
import com.ymatou.productstock.api.service.ReturnProductActivityStockCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.NewJavaMongoCheckService;
import com.ymttest.business.service.ProductStockCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.mongo.ProductActivityStockInfoWapper;
import com.ymttest.database.mongo.ProductStockInfoWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.ProductTimeStampBean;
import com.ymttest.database.mongo.jproduct.ProductTimeStampWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;

public class Ts_AllocateProductActivityStock {
	//base data
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static int activityStartId = Integer.parseInt(EnvSetup.getData("productActivityStartId"));
	private static String activityUser = EnvSetup.getData("AdminLoginUser");
	private static String activityPswd = EnvSetup.getData("AdminLoginPswd");
	
	//sql db
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static YmtProductActivityStockWapper ymtProductActivityStockWapper = new YmtProductActivityStockWapper();
	private static YmtProductsInActivityWapper ymtProductsInActivityWapper = new YmtProductsInActivityWapper();
	
	
	
	//mongo db
	private static ProductStockInfoWapper productStockInfoWapper=new ProductStockInfoWapper();
	private static ProductActivityStockInfoWapper productActivityStockInfoWapper= new ProductActivityStockInfoWapper();
	private static ProductTimeStampWapper productTimeStampWapper = new ProductTimeStampWapper();
	
	//API
	private static AllocateProductActivityStockCall allocateProductActivityStockCall = new AllocateProductActivityStockCall();
	private static ReturnProductActivityStockCall returnProductActivityStockCall = new ReturnProductActivityStockCall();

	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("调拨活动库存");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(allocateProductActivityStockCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_001() {
		Logger.start(true, "调拨活动库存,活动解锁返库存");
		try{
			
			Logger.comment("调拨活动库存");
			String productId = SellerProductCallService.addNewProductAndApproveActivity(sellerId,
					sellerName,activityUser,activityPswd,String.valueOf(activityStartId),null);
			
			//时间戳检查
			ProductTimeStampBean productTimeStampBean = new ProductTimeStampBean();
			productTimeStampBean.setProductId(productId);
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				Map<String, Object> ret = productTimeStampWapper.getByProductId(productId);
				productTimeStampBean.setSut((Date)ret.get("sut"));
				productTimeStampBean.setCut((Date)ret.get("cut"));
				productTimeStampBean.setAut((Date)ret.get("aut"));
			}
			
			YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalogsI.getsCatalogId();
			int catalogNum = ymtCatalogsI.getiNum();//共享库存
			String sku = ymtCatalogsI.getsSKU();
			
			YmtProductActivityStock ymtActivityStock = ymtProductActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			
			int productinActivityId = ymtProductsInActivityWapper.selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productinActivityId);
			
			
			int allocateStock = 2;//调拨库存数量
			
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductActivityId", productinActivityId);
			updateMap.put("ProductId", productId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku);
			updateMap.put("FBXCatalogLockList[0]->Stock", allocateStock);
			
			JSONObject retBean = allocateProductActivityStockCall.callAndGetReturnData(updateMap);
			
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			JSONObject dataBean = retBean.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchModifyResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap = MapUtil.hashMap("ActivityID", activityStartId, 
															"ProductId", productId, 
															"ProductActivityId",productinActivityId,
															"Status",1,
															"CatalogId",catalogId);
			
			AssertService.assertResultEqual(tgtRetMap, MapUtil.jsonToMap(dataBean));
			
			
			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum-allocateStock, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			YmtProductActivityStock ymtProductActivityStock=ymtProductActivityStockWapper.selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId, //商品规格Id
															"istocknum",activityNum+allocateStock,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductActivityStock),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum-allocateStock),productStockInfoWapper.getByCatalogId(catalogId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = productActivityStockInfoWapper.getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId, //商品规格Id
																		"ActivityStockNum",(activityNum+allocateStock),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum-allocateStock);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum+allocateStock);
				stockBean2.setProductInActivityId(productinActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
		
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productinActivityId);
				
				Map<String, Object> ret = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(false,productTimeStampBean.getCut().equals((Date)ret.get("cut")),"ProductTimeStamp cut应该变化");
				Logger.verifyEquals(false,productTimeStampBean.getAut().equals((Date)ret.get("aut")),"ProductTimeStamp aut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().equals((Date)ret.get("sut")),"ProductTimeStamp sut应该没有变化");
			
				productTimeStampBean.setSut((Date)ret.get("sut"));
				productTimeStampBean.setCut((Date)ret.get("cut"));
				productTimeStampBean.setCut((Date)ret.get("aut"));
			}
			
			
			//==========================================================================================
			Logger.comment("活动解锁返库存");
			
			Map<String, Object> returnStockMap = MapUtil.hashMap("UserID", sellerId, 
																 "ActivityID", activityStartId, 
																 "ProductID", productId,
																 "ProductActivityId",productinActivityId);
			
			JSONObject retJson = returnProductActivityStockCall.callAndGetReturnData(returnStockMap);
			Logger.verifyEquals(200, retJson.getInt("Code"), "响应报文-返回码");
			JSONObject retdataBean = retJson.getJSONObject("Data").getJSONArray("BatchCancelResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap2 = MapUtil.hashMap("ReturnStockStatus", 1,"ProductId", productId,"SKU",sku);
			
			AssertService.assertResultEqual(tgtRetMap2, MapUtil.jsonToMap(retdataBean));
			
			
			
			//check sql
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum+activityNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			ymtProductActivityStock=ymtProductActivityStockWapper.selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap2 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId, //商品规格Id
															"istocknum",0,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap2, MapUtil.pojoToMap(ymtProductActivityStock),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum+activityNum),productStockInfoWapper.getByCatalogId(catalogId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = productActivityStockInfoWapper.getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId, //商品规格Id
																		"ActivityStockNum",0,//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum+activityNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(0);
				stockBean2.setProductInActivityId(productinActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productinActivityId);
				
				Map<String, Object> ret = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(false,productTimeStampBean.getAut().equals((Date)ret.get("aut")),"ProductTimeStamp aut应该变化");
				Logger.verifyEquals(false,productTimeStampBean.getCut().equals((Date)ret.get("cut")),"ProductTimeStamp cut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().equals((Date)ret.get("sut")),"ProductTimeStamp sut应该没有变化");
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void  Tc_AllocateProductActivityStock_002() {
		Logger.start(true, "多规格报名 调拨活动库存,活动解锁返库存");
		try{
			
			Logger.comment("调拨活动库存");
			
			int catalogAllNum = 10;
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc9.json");
			JSONArray CatalogListBean = addProductBean.getJSONObject("Product").getJSONArray("Catalogs");
			JSONObject CatalogFirst = CatalogListBean.getJSONObject(0);
			for(int i=1;i<catalogAllNum;i++){
				CatalogListBean.put(i, new JSONObject(CatalogFirst.toString()));
				
				CatalogListBean.getJSONObject(i).getJSONArray("PropertyValues").getJSONObject(1).getJSONArray("PropertyValues").getJSONObject(0).put("PropertyValue",String.valueOf(100+i));
			}
			
			
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productId);
			}
			
			
			//报名参加活动
			SellerProductCallService.approveActivity(sellerId,activityUser,activityPswd,String.valueOf(activityStartId),productId);
			
			
			YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalogsI.getsCatalogId();
			int catalogNum = ymtCatalogsI.getiNum();//共享库存
			String sku = ymtCatalogsI.getsSKU();
			
			YmtProductActivityStock ymtActivityStock = ymtProductActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			
			int productinActivityId = ymtProductsInActivityWapper.selectByProductId(productId).getIproductinactivityid();
			Logger.debug("ProductInActivityId: "+ productinActivityId);
			
			
			int allocateStock = 2;//调拨库存数量
			
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductActivityId", productinActivityId);
			updateMap.put("ProductId", productId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku);
			updateMap.put("FBXCatalogLockList[0]->Stock", allocateStock);
			
			JSONObject retBean = allocateProductActivityStockCall.callAndGetReturnData(updateMap);
			
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			JSONObject dataBean = retBean.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchModifyResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap = MapUtil.hashMap("ActivityID", activityStartId, 
															"ProductId", productId, 
															"ProductActivityId",productinActivityId,
															"Status",1,
															"CatalogId",catalogId);
			
			AssertService.assertResultEqual(tgtRetMap, MapUtil.jsonToMap(dataBean));
			
			
	
		
			//new mongo
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productId);
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productinActivityId);
			}
			
			
			
			//==========================================================================================
			Logger.comment("活动解锁返库存");
			
			Map<String, Object> returnStockMap = MapUtil.hashMap("UserID", sellerId, 
																 "ActivityID", activityStartId, 
																 "ProductID", productId,
																 "ProductActivityId",productinActivityId);
			
			JSONObject retJson = returnProductActivityStockCall.callAndGetReturnData(returnStockMap);
			Logger.verifyEquals(200, retJson.getInt("Code"), "响应报文-返回码");
			JSONObject retdataBean = retJson.getJSONObject("Data").getJSONArray("BatchCancelResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap2 = MapUtil.hashMap("ReturnStockStatus", 1,"ProductId", productId,"SKU",sku);
			
			AssertService.assertResultEqual(tgtRetMap2, MapUtil.jsonToMap(retdataBean));
			
			
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productId);
				NewJavaMongoCheckService.checkActivityProductMgoSyncBySQL_NewJavaMgo(productinActivityId);
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	/*@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_002() {
		Logger.start(true, "多规格 调拨活动库存,活动解锁返库存");
		try{
			
			Logger.comment("调拨活动库存");
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			
			//规格1 参加活动
			YmtCatalogsI ymtCatalogsI1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId1 = ymtCatalogsI1.getsCatalogId();
			
			YmtCatalogsI ymtCatalogsI2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogId2 = ymtCatalogsI2.getsCatalogId();
			
			
			SellerProductCallService.approveActivity( sellerId,activityUser,activityPswd,String.valueOf(activityStartId),productId,catalogId1);
			SellerProductCallService.approveActivity( sellerId,activityUser,activityPswd,String.valueOf(activityStartId),productId,catalogId2);
			
			
			YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId);
			String sku = ymtCatalogsI.getsSKU();
			int catalogNum = ymtCatalogsI.getiNum();//共享库存
			
			YmtProductActivityStock ymtActivityStock = ymtProductActivityStockWapper.selectByCatalogId(catalogId);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			int productinActivityId = ymtActivityStock.getIproductinactivityid();
			
			int allocateStock = (i%2==0)?3:4;//调拨库存数量
			
			Map<String, Object> updateMap = new HashMap<String,Object>();
			updateMap.put("UserID", sellerId);
			updateMap.put("ActivityID", activityStartId);
			updateMap.put("ProductActivityId", productinActivityId);
			updateMap.put("ProductId", productId);
			updateMap.put("IsFbxProduct", false);
			updateMap.put("FBXCatalogLockList[0]->CatalogId", catalogId);
			updateMap.put("FBXCatalogLockList[0]->Sku", sku);
			updateMap.put("FBXCatalogLockList[0]->Stock", allocateStock);
			
			JSONObject retBean = allocateProductActivityStockCall.callAndGetReturnData(updateMap);
			
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			JSONObject dataBean = retBean.getJSONObject("Data").getJSONObject("XLoboResult").getJSONArray("BatchModifyResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap = MapUtil.hashMap("ActivityID", activityStartId, 
															"ProductId", productId, 
															"ProductActivityId",productinActivityId,
															"Status",1,
															"CatalogId",catalogId);
			
			AssertService.assertResultEqual(tgtRetMap, MapUtil.jsonToMap(dataBean));
			
			//check sql
			//SQL-Ymt_Catalogs
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId);
			Logger.verifyEquals(catalogNum-allocateStock, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			YmtProductActivityStock ymtProductActivityStock=ymtProductActivityStockWapper.selectByCatalogId(catalogId);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId, //商品规格Id
															"istocknum",activityNum+allocateStock,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductActivityStock),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum-allocateStock),productStockInfoWapper.getByCatalogId(catalogId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = productActivityStockInfoWapper.getByProductActivityId(productinActivityId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId, //商品规格Id
																		"ActivityStockNum",(activityNum+allocateStock),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum-allocateStock);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum+allocateStock);
				stockBean2.setProductInActivityId(productinActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean),false);
			}
			
			
			//==========================================================================================
			Logger.comment("活动解锁返库存");
			
			Map<String, Object> returnStockMap = MapUtil.hashMap("UserID", sellerId, 
																 "ActivityID", activityStartId, 
																 "ProductID", productId,
																 "ProductActivityId",productinActivityId);
			
			JSONObject retJson = returnProductActivityStockCall.callAndGetReturnData(returnStockMap);
			Logger.verifyEquals(200, retJson.getInt("Code"), "响应报文-返回码");
			JSONObject retdataBean = retJson.getJSONObject("Data").getJSONArray("BatchCancelResults").getJSONObject(0);
			
			Map<String,Object> tgtRetMap2 = MapUtil.hashMap("ReturnStockStatus", 1,"ProductId", productId,"SKU",sku);
			
			AssertService.assertResultEqual(tgtRetMap2, MapUtil.jsonToMap(retdataBean));
			
			//check sql
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId);
			Logger.verifyEquals(catalogNum+activityNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock 商品库存数量
			ymtProductActivityStock=ymtProductActivityStockWapper.selectByCatalogId(catalogId);
			Map<String, Object> tgtsqlMap2 = MapUtil.hashMap("sproductid", productId, //商品Id
															"scatalogid",catalogId, //商品规格Id
															"istocknum",0,//库存数量
															"iactivityid",activityStartId); //活动Id
			
			AssertService.assertResultEqual(tgtsqlMap2, MapUtil.pojoToMap(ymtProductActivityStock),"SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//check mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum+activityNum),productStockInfoWapper.getByCatalogId(catalogId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = productActivityStockInfoWapper.getByProductActivityId(productinActivityId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogId, //商品规格Id
																		"ActivityStockNum",0,//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum+activityNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean),false);
			}
			
			
			
			
			
			
			
			
			
			
			
	
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	*/
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
